package AddProduct;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.http.HttpServletResponse;

/**
 * This class contain methods which is used by servlets.
 * @author desso_000
 */
public class HTML {
	public static void printSelect(PrintWriter prinWriter, ResultSet resultSet, String table) throws SQLException {
		prinWriter.println(" <p>" + table + "</p>");
		prinWriter.println(" <select name=\"" + table + "\"> ");	
		while(resultSet.next()) {
			prinWriter.println("<option value=\"" + resultSet.getInt(1) + "\">" + resultSet.getString(2) + " </option>");
		}	
		prinWriter.println(" </select> "); 
	}
	
	public static void printItems(PrintWriter prinWriter, ResultSet resultSet) throws SQLException {
		  prinWriter.println(" <select name=\"item\"> ");	
		    while(resultSet.next()) {
			    prinWriter.println("<option value=\"" + resultSet.getInt(1) + "\">" + resultSet.getString(2)+ " ("+ resultSet.getString(3) + ")  " + " </option>");
			}	
		  prinWriter.println(" </select> "); 	
	}
	
	public static void PrintASuccessMessage(HttpServletResponse response, String message) throws IOException {
		PrintWriter prinWriter = response.getWriter();
		response.setContentType("text/html");
		prinWriter.println("<!DOCTYPE html>");
		prinWriter.println("<html>");
		prinWriter.println("<h1> 	NEW " + message.toUpperCase() + " WAS ADDED SUCCESSFULLY! </h1>");
		prinWriter.println("</html>");
	}

}
